Number Count is the largest script included with this release of Pfhortran,
and is the script that Krinkle uses to do its cool number flashing. Since
Pfhortran doesn't yet support comments (next version, promise!), this file
is here to explain how Number Count works.

First of all, the Krinkle map consists of a balcony looking over a dark
space. Numbers flash in the space counting from 0 to 9. Tagged lights are
used to display the numbers. The digit polygons look pretty much like any
old digit on your calculator: Any number between 0 and 9 can be created by
hilighting the right elongated diamond shape.

Number Count keeps a variable called total around to remember what number is
supposed to be displayed. It also has another variable called tag that tells
if the switch in the "tower" room has been clicked on or not.


total: def 0
tag: def 0

	This defines the variables total and tag and puts zero as the
	initial value for both.

set_tag_state 1, FALSE

	Tag 1 is controlled by the switch in the tower.  We want it to start
	off, so we set the state of tag 1 to false.

top: wait_ticks 150
get_tag_state 1, tag
if_equal tag, FALSE, next
inflict_damage total
set_tag_state 1, FALSE


	This is the first part of the main script.  The label 'top' is
	defined so we can jump back to this location later. wait_ticks 150
	tells Pfhortran to wait 150 game ticks before executing the next
	instruction. Every time we change the number, we want to see if the
	player has clicked the tower button on. As clicking this button has
	the effect of damaging the player, we will refer to this button as
	the "pain button". The pain button controls tag 1. By checking the
	value of Tag 1, we can check to see if the button is on. This is
	done with get_tag_state. The state of tag 1 is returned in the
	variable tag, which is then compared to FALSE in the next statement,
	if_equal. If_Equal compares the two values passed and jumps to the
	label specified last if the values are equal. So in this case, if
	tag = FALSE, i.e tag 1 is not turned on, skip over to the label
	'next' (below). If we get to the next line, it means that tag 1 =
	TRUE, so the button is on. In this case, we want to inflict some
	damage on the player and then turn the button off. We do this by
	calling inflict_damage and we pass total (the value being shown in
	the dark room) as the amount of damage to inflict. Then we turn the
	button off by setting the state of Tag 1 to FALSE.


next: add total, 1
jump dim
check: if_equal total, 10, ten
if_equal total, 0, zero
if_equal total, 1, one
if_equal total, 2, two
if_equal total, 3, three
if_equal total, 4, four
if_equal total, 5, five
if_equal total, 6, six
if_equal total, 7, seven
if_equal total, 8, eight
if_equal total, 9, nine
set total, 0
jump top


	Continuing on to 'next', we go ahead and increment total by one.  We
	then jump to 'dim', which is described below. 'Dim' turns all the
	lights off in preparation for our new number to be displayed. From
	'check' we proceed to check every possible value of total and jump
	to the right location. If total equals 4, for instance, the script
	will jump to the label called 'four'. Each of these labels jumps
	back to the 'top' label at the top of the script, so we should never
	get past the "if_equal total, 9, nine" line. Just in case something
	went wrong and we do go past it, set total back to zero and jump to
	the beginning.


dim: set_tag_state 9, FALSE
set_tag_state 10, FALSE
set_tag_state 11, FALSE
set_tag_state 12, FALSE
set_tag_state 13, FALSE
set_tag_state 14, FALSE
set_tag_state 15, FALSE
jump check


	'Dim' is responsible for dimming all the lights in our dark room
	that we use to display our number. It just so happens that the
	lights we use are tagged from 9 to 15 (9 being the bottom diamond
	and continuing around the 8 counter-clockwise, with 11 as the center
	bar). In order to turn off all these lights, we simply need to set
	the states of the tags associated with each light to false. Thats
	what 'dim' does. When it's done, it jumps back to 'check' (above).


zero: set_tag_state 9, TRUE
set_tag_state 10, TRUE
set_tag_state 12, TRUE
set_tag_state 13, TRUE
set_tag_state 14, TRUE
set_tag_state 15, TRUE
jump top

	'Zero' works a whole lot like 'dim', but it only turns on a specific
	number of lights. To make the character '0', we need to turn on all
	the lights except for the middle bar one (which is light tag 11).
	So, 'zero' simply sets the states of each light it wants on to TRUE.
	Since 'dim' was called before this, we can assume that all the other
	lights are off. All of the other numbers are written like 'zero' is,
	varying only in which lights get turned on. When finished, they all
	jump back up to top.


ten: set total, 0
jump check


	The only value left then, is 10.  Ten is not displayable because it
	requires two digits, so we set total to zero and jump back on up.
	This way, the script repeats for ever.
